<?php

namespace App\Models\Fund;

use App\Models\BaseModel;
use App\Models\Cargo\WayBill;

/**
 * 资金账户
 *
 * Class FundOptionLog
 * @package App\Models\Fund
 */
class FundOptionLog extends BaseModel
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'fund_option_log';

    /**
     * Indicates if the model should be timestamped.
     * @var bool
     */
    public $timestamps = false;
    public $appends = ['type_text','status_text'];
    public $typeText = [
        'init'=>'初始化',
        'prepaid'=>'系统充值',
        'transfer'=>'转账',
        'payment'=>'支付',
        'borrow'=>'借款',
        'refund'=>'还款',
        'freeze'=>'冻结',
        'unfreeze'=>'解冻',
        'system'=>'系统',
        'deposit' => '保证金'
    ];

    public function getTypeTextAttribute()
    {
        return $this->typeText[$this['type']];
    }

    public function getUserInfoAttribute($value)
    {
        return json_decode($value, true);
    }

    public function getOppositeInfoAttribute($value)
    {
        return json_decode($value, true);
    }

    public function waybill()
    {
        return $this->hasOne(WayBill::class, 'id', 'waybill_id')
            ->select('id', 'number', 'created_at', 'updated_at', 'start_addr', 'end_addr');
    }

}
